var data1 = []
var layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form,$ = layui.jquery,laydate = layui.laydate;
var isMsn="否";
lay('.starttime').each(function(){
    laydate.render({
        elem: this
    });
});
function getAllJson(jsons) {
    let tmpitem=[]
    for (let item of jsons) {
        let tmparr={}
        tmparr["value"]=item["code"];
        tmparr["name"]=item["name"];
        if(item["users"]){
            for(let it of item["users"]){
                item["list"].push(it)
            }
        }
        if(item["list"] && item["list"].length){
            tmparr["children"]=   this.getAllJson(item["list"]);
            tmpitem.push(tmparr)
        }else{
            tmpitem.push(tmparr)
        }

    }
    return tmpitem
}

function getxmselect(el,name, data) {
    return demo1=xmSelect.render({
        el: el,
        name: name,
        tree: {
            show: true,
            showLine: true,
            showFolderIcon:true,
            indent: 20,
            expandedKeys:false,
            clickExpand: true,
        },
        height: 'auto',
        data: data,
        on: function ({ arr, change, isAdd }) {
            return this
        }
    })
}
//获取所有用户所管理的部门
function getAllDepartmentUser() {
    let userTree = {};
    $.ajax({
        type: 'get',
        url: 'department/getAllDepartmentUser',
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.status == 200) {
                userTree = data.data;
            }
        },
        error: function (data) {
        }
    });
    return userTree;

}
//select over
(function () {
    //获取当前用户的部门及人员结构树
    let treeList = getAllDepartmentUser();
    if(treeList && treeList.list){
        let userTree = getAllJson(treeList.list);
        getxmselect("#operationCode","operationCode", userTree);
        getxmselect("#salesmanCode","salesmanCode", userTree);
    }else {
        getxmselect("#operationCode","operationCode", [{name: user.name, value: user.code}]);
        getxmselect("#salesmanCode","salesmanCode", [{name: user.name, value: user.code}]);
    }

})()

//回调函数
var callbackdata = function () {
    //提交第一步，获取到联系人的所有email地址
    var s1=demo1.getValue();
    var code=''
    var idea=$("#idea").val()
    if(s1.length>0){
        for(let i in s1){
            code+=s1[i].value+","
        }
    }
    var data = {
        "code":code,
        "idea":idea
    };
    return data;
}
